<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>添加地址</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.
">
<link rel="stylesheet" href="resources/css/weui.min.css">
<link rel="stylesheet" href="resources/css/jquery-weui.css">
<link rel="stylesheet" href="resources/css/style.css">
</head>


<body ontouchstart>
<!--主体-->
<header class="wy-header">
  <div class="wy-header-icon-back"><span></span></div>
  <div class="wy-header-title">添加地址</div>
</header>
<div class="weui-content">
  <div class="weui-cells weui-cells_form wy-address-edit">
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">收货人</label></div>
      <div class="weui-cell__bd"><input class="weui-input" type="text" name="name"/></div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">手机号</label></div>
      <div class="weui-cell__bd"><input class="weui-input" type="number" pattern="[0-9]*" name="moblie"/></div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">详细地址</label></div>
      <div class="weui-cell__bd">
        <textarea class="weui-textarea" name="address"></textarea>
      </div>
    </div>
    <div class="weui-cell weui-cell_switch">
      <div class="weui-cell__bd">设为默认地址</div>
      <div class="weui-cell__ft"><input class="weui-switch" type="checkbox" name="contactFlag"></div>
    </div>
  </div> 
  <div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary" href="javascript:submit();" id="showTooltips">保存此地址</a>
  </div>

</div>




<script src="resources/js/jquery.min.js"></script>
<script src="resources/js/fastclick.js"></script> 
<script src="resources/js/jquery-weui.min.js"></script>
<script type="text/javascript">
// 提交数据
function submit(){
	let userId = 245;
	let name = $("input[name='name']").val();
	let moblie = $("input[name='moblie']").val();
	let address = $("textarea[name='address']").val();
	let contactFlag = ($("input[name='contactFlag']").is(":checked") ? 1 : 0);
	if(name == ''){$.alert("请填写你的真实姓名");}
	else if(moblie == ''){$.alert("请填写你的联系电话");}
	else if(address == ''){$.alert("请填写你的收货地址");}
	else{
		$.post('api/v1/user/add/contect',{userId,name,moblie,address,contactFlag},({errorCode})=>{
        	if(errorCode==0){location.href="addressList";}
        	else{$.toast("添加失败", "cancel");}
        }).error(()=>{$.toast("添加失败", "cancel");});
	}
}
// 回退
$(".wy-header-icon-back").click(()=>{location.href="addressList";})
// fastclick  
$(function() {
  FastClick.attach(document.body);
});
</script>
</body>
</html>
